home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / URL Helper II / Source / URLHelperStandard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-13  |  3.2 KB  |  166 lines  |  [TEXT/MMCC]

  1. /***
  2.  * URLHelperComponentStandard.c
  3.  *
  4.  *  Routines to implement the target and register stuff for this component.
  5.  *
  6.  ***/
  7.  
  8. #include "debug_me.h"
  9. #include "URLHelperComponent.h"
  10. #include "URLHelperComponentPrivate.h"
  11. #include "Exceptions.h"
  12.  
  13. /**
  14.  * _URLHelperOpen
  15.  *
  16.  *  This guy is begin opened.  Allocate the global storage we need to use.
  17.  *
  18.  **/
  19. pascal ComponentResult _URLHelperOpen (Handle storage, ComponentInstance theComp)
  20. {
  21.     URLGlobalsHandle    globalsHandle;
  22.     URLGlobalsPtr        globals;
  23.     OSErr                    theErr;
  24.  
  25.     /**
  26.      ** Try to allocate our globals.  If we can't, then we are in some
  27.      ** big time trouble and we need to bail out.
  28.      **/
  29.  
  30.     globalsHandle = (URLGlobalsHandle) NewHandleClear (sizeof(URLGlobals));
  31.     theErr = MemError ();
  32.     require (globalsHandle != 0, FailedAllocateGlobals);
  33.  
  34.     /**
  35.      ** Install the globals as our instance variables
  36.      **/
  37.  
  38.     SetComponentInstanceStorage (theComp, (Handle) globalsHandle);
  39.  
  40.     /**
  41.      ** To make the rest simple, lock the globals handle down and deref it
  42.      **/
  43.  
  44.     HLock ((Handle) globalsHandle);
  45.     globals = *globalsHandle;
  46.  
  47.     /**
  48.      ** Remember who we are so that we can call ourselves in other routines.
  49.      **/
  50.     
  51.     globals -> self = theComp;
  52.     globals -> mirrorList = 0;
  53.  
  54.     /**
  55.      ** Done!  We can return no err now...
  56.      **/
  57.  
  58.     HUnlock ((Handle) globalsHandle);
  59.  
  60.     return noErr;
  61.  
  62.     /**
  63.      ** Handle all the errors that occured during setup
  64.      **/
  65.  
  66.  
  67. FailedAllocateGlobals:
  68.     return theErr;
  69. }
  70.  
  71. /**
  72.  * _URLHelperClose
  73.  *
  74.  *  Close this instance down.  Deallocate the instance storage...
  75.  *
  76.  **/
  77. pascal ComponentResult _URLHelperClose (Handle storage, ComponentInstance self)
  78. {
  79.     URLGlobalsHandle    globals = (URLGlobalsHandle) storage;
  80.  
  81.     /**
  82.      ** Make sure the globals are non zero...
  83.      **/
  84.     
  85.     if (globals != 0) {
  86.         DisposHandle ((Handle) globals);
  87.         SetComponentInstanceStorage (self, 0L);
  88.     }
  89.  
  90.     return noErr;
  91. }
  92.  
  93. /**
  94.  * _URLHelperCanDo
  95.  *
  96.  *  Return true if we can actually perform some function
  97.  *
  98.  **/
  99. pascal ComponentResult _URLHelperCanDo (short selector)
  100. {
  101.     switch (selector) {
  102.  
  103.                                         // The component manager request codes
  104.         case kComponentOpenSelect:
  105.         case kComponentCloseSelect:
  106.         case kComponentCanDoSelect:
  107.         case kComponentVersionSelect:
  108.         case kComponentTargetSelect:
  109.  
  110.                                         // Our URLHelper component request codes
  111.         case kDoGetMirrorList:
  112.         case kDoNewMirrorList:
  113.         case kDoAddMirror:
  114.         case kDoNumberOfMirrors:
  115.         
  116.             return true;
  117.             break;
  118.         
  119.                                         // All else, we can't do
  120.         default:
  121.             return false;
  122.     }
  123. }
  124.  
  125. /**
  126.  * _URLHelperVersion
  127.  *
  128.  *  Return the interface revision number
  129.  *
  130.  **/
  131. pascal ComponentResult _URLHelperVersion (void)
  132. {
  133.     return URLHelperInterfaceRevision;
  134. }
  135.  
  136. /**
  137.  * _URLHelperTarget
  138.  *
  139.  *  Someone is going to capture us for later use.  Save the targeting compontent
  140.  *  for later internal use
  141.  *
  142.  **/
  143. pascal ComponentResult _URLHelperTarget (Handle storage, ComponentInstance capturingComponent)
  144. {
  145.     URLGlobalsHandle    globals = (URLGlobalsHandle) storage;
  146.     OSErr                theErr;
  147.  
  148.     /**
  149.      ** Make sure all is ok
  150.      **/
  151.  
  152.     theErr = paramErr;
  153.     require (globals != 0 && capturingComponent != 0, BadParams);
  154.     theErr = noErr;
  155.  
  156.     /**
  157.      ** Ok -- save the component instance so we can use it to call our own routines
  158.      **/
  159.     
  160.     (*globals) -> self = capturingComponent;
  161.  
  162. BadParams:
  163.     return theErr;
  164.  
  165. }
  166.